/**
 * Created by Administrator on 2017/4/26 0026.
 */
/**
 *setcookie 设置cookie
 * @param key
 * @param value
 * @param num
 * @param secure
 */

function setcookie(key,value,num,secure) {
    var tmp = "";
    if (key) {
        tmp = encodeURIComponent(key) + "=" + encodeURIComponent(value) + ";";
    }
    if (!num) {
    } else {
        var date = new Date();
        date.setDate(date.getDate() + parseInt(num));
        tmp += "expires=" + date + ";";
    }
    if (secure) {
        tmp += "secure;";
    }
    document.cookie = tmp;
}

function getcookie() {
    var obj={};
    var tmp=decodeURIComponent(document.cookie.replace(/ /g,""));
    if(tmp.indexOf(";")!=-1){
        var str=tmp.split(";");
        for(var i=0;i<str.length;i++){
            var arr=str[i].split("=");
            obj[arr[0].trim()]=arr[1];
        }
    }else {
        var str=tmp.split("=");
        obj[str[0]]=str[1];
    }
    return obj;
    console.log(obj);

}



function getcookiebykey(key) {
    var obj=getcookie(key);
    return obj[key];
}



